home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / BKISSSRC.ZIP / SINUS / SINUS.ASM < prev   
Encoding:
Assembly Source File  |  1994-02-11  |  5.9 KB  |  202 lines

  1. ideal
  2. locals
  3. jumps
  4. model huge
  5. stack 100h
  6. p386
  7.  
  8. TextMode = 0
  9. NumFrames = 4000                    ;number of frames to do before quitting
  10. MaxBobs = 75                        ;maximum number of active bobs
  11. HeartWidth = 32                     ;\ dimensions of the image
  12. HeartHeight = 25                    ;/
  13. XRadius = 120                       ;\ radius of path
  14. YRadius = 60                        ;/
  15. Phase1Inc = 2                       ;\ amount to add to phase
  16. Phase2Inc = 3                       ;/
  17.  
  18. segment     MyData
  19. FramesLeft  dw NumFrames            ;number of frames left
  20. BobBuffer   dd MaxBobs dup (-1)     ;our buffer containing X and Y of each bob
  21. NextSlot    dw 0                    ;pointer into next available slot
  22. Row         dw 100                  ;\ computed coordinates
  23. Col         dw 100                  ;/
  24. Angle       dw 0                    ;\
  25. Phase1      dw 2*1024               ; > used during computation
  26. Phase2      dw 2*1024               ;/
  27. extrn       HeartImage:byte         ;this is the image
  28. extrn       PaletteData:byte        ;this should be a RGB triplet palette
  29. ends        MyData
  30.  
  31. segment     MyCode
  32.             assume cs:MyCode, ds:MyData
  33. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  34. include     "sincos.inc"
  35. include     "modex.inc"
  36. include     "bitmap.inc"
  37. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  38. proc        Start
  39.             ;set up all of the segments
  40.             cld
  41.             mov ax,MyData
  42.             mov ds,ax
  43.  
  44.             ;switch over to graphics mode
  45.             @SetModeX M320x200x256,320
  46.             ScreenWidth = 320
  47.             ScreenHeight = 200
  48.  
  49.             ;load in the palette
  50.             mov si,offset PaletteData
  51.             mov cx,256
  52.             mov al,0
  53.             @WritePalette
  54.  
  55. @@MainLoop: call RefreshScreen
  56.  
  57.             dec [FramesLeft]
  58.             jz @@AllDone
  59.             
  60.             ;get stdio.  If something's been pressed, quit
  61.             mov ah,6
  62.             mov dl,0FFh
  63.             int 21h
  64.             jz @@MainLoop
  65.  
  66. @@AllDone:  call DeleteAll
  67.  
  68.             ;change back to text mode and quit
  69.             if TextMode ne 0
  70.                 mov ax,0003h
  71.                 int 10h
  72.             endif
  73.             mov ax,4C00h
  74.             int 21h
  75. endp        Start
  76. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  77. proc        RefreshScreen
  78.             ;wait for a retrace (for timing)
  79.             @FullVertWait
  80.  
  81.             ;compute the coordinates of the next bob
  82.             call ComputePos
  83.  
  84.             ;get a pointer to the next slot
  85.             mov si,[NextSlot]
  86.             shl si,2
  87.             add si,offset BobBuffer
  88.  
  89.             ;erase the old bob, if the slot is occupied
  90.             cmp [dword ds:si],-1
  91.             jz @@EmptySlot
  92.             push (seg HeartImage) (offset HeartImage)
  93.             push HeartHeight HeartWidth
  94.             push 0
  95.             push [word ds:si+2] [word ds:si+0]
  96.             call sub_bitmap
  97.             add sp,14
  98.  
  99. @@EmptySlot:;save the coordinates
  100.             mov ax,[Col]
  101.             mov [word ds:si+0],ax
  102.             mov ax,[Row]
  103.             mov [word ds:si+2],ax
  104.  
  105.             ;display the bob
  106.             push (seg HeartImage) (offset HeartImage)
  107.             push HeartHeight HeartWidth
  108.             push 0
  109.             push [Row] [Col]
  110.             call add_bitmap
  111.             add sp,14
  112.  
  113.             ;update our pointer
  114.             inc [NextSlot]
  115.             cmp [NextSlot],MaxBobs
  116.             jb @@Quit
  117.             mov [NextSlot],0
  118. @@Quit:     ret
  119. endp        RefreshScreen
  120. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  121. proc        DeleteAll
  122.             ;wait for a retrace (for timing)
  123.             @FullVertWait
  124.  
  125.             ;get a pointer to the next slot
  126.             mov si,[NextSlot]
  127.             shl si,2
  128.             add si,offset BobBuffer
  129.  
  130.             cmp [dword ds:si],-1
  131.             jz @@EmptySlot
  132.             cmp [dword ds:si],-2
  133.             jz @@Quit
  134.             ;erase the old bob, if the slot is occupied
  135.             push (seg HeartImage) (offset HeartImage)
  136.             push HeartHeight HeartWidth
  137.             push 0
  138.             push [word ds:si+2] [word ds:si+0]
  139.             call sub_bitmap
  140.             add sp,14
  141.             mov [dword ds:si],-2
  142. @@EmptySlot:;update our pointer
  143.             inc [NextSlot]
  144.             cmp [NextSlot],MaxBobs
  145.             jb DeleteAll
  146.             mov [NextSlot],0
  147.             jmp DeleteAll
  148.  
  149. @@Quit:     ret
  150. endp        DeleteAll
  151. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  152. proc        ComputePos
  153.             ;compute the column
  154.             mov ax,[Angle]
  155.             imul [Phase1]
  156.             mov bl,ah
  157.             mov bh,dl
  158.             shr bx,2
  159.             xor bh,bh
  160.             mov al,[Cosine+bx]
  161.             mov ah,XRadius
  162.             imul ah
  163.             sar ax,6
  164.             add ax,(ScreenWidth-HeartWidth)/2
  165.             mov [Col],ax
  166.  
  167.             ;compute the row
  168.             mov ax,[Angle]
  169.             imul [Phase2]
  170.             mov bl,ah
  171.             mov bh,dl
  172.             shr bx,2
  173.             xor bh,bh
  174.             mov al,[Sine+bx]
  175.             mov ah,YRadius
  176.             imul ah
  177.             sar ax,6
  178.             add ax,(ScreenHeight-HeartHeight)/2
  179.             mov [Row],ax
  180.  
  181.             ;increment angle
  182.             inc [Angle]
  183.             and [Angle],1023
  184.  
  185.             ;increment phase 1
  186.             add [Phase1],Phase1Inc
  187.             cmp [Phase1],5*1024
  188.             jb @@Phase1Ok
  189.             sub [Phase1],5*1024
  190. @@Phase1Ok:
  191.             ;increment phase 2
  192.             add [Phase2],Phase2Inc
  193.             cmp [Phase2],5*1024
  194.             jb @@Phase2Ok
  195.             sub [Phase2],5*1024
  196. @@Phase2Ok:
  197.             ret
  198. endp        ComputePos
  199. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  200. ends        MyCode
  201.             end     Start
  202.